/**
 * 编辑-课题js
 */
var vm = new Vue({
	el:'#dpLTE',
	data: {
		srbliveClassroom: {
			id: 0,
            moneytype:0,/* 课题费用类型，0为免费，1为付费，2为加密 */
            // active:1,
            status:1,//课程状态: 1为正常,0为课程结束
            hascomment:1,
            hastip:1,
            type:0,
            livetype:null,
            liveparenttype:null,
            price:null,
		},
        livetype:null,
        liveparenttypes:[],
        livetypes:[],
        config:{},
        ue:UE.getEditor('srbliveClassroom-content')
	},
    watch: {
        "srbliveClassroom.liveparenttype": function (val, oldval) {
            if (val !== oldval) {
                var _vm = this;
                if(_vm){
                    Utils.getLiveRoomTypes({
                        pid: val,
                        serviceType:'getSon',
                        success: function (result) {
                            _vm.livetypes = result.rows;
                        }
                    });
                }
            }
        },
        "srbliveClassroom.moneytype":function (val, oldval) {
            if (val !== oldval) {
                //切换到加密时，清楚价格信息
                if(val!=1) vm.srbliveClassroom.price = null;
            }
        }
    },
	methods : {
		setForm: function() {
			$.SetForm({
				url: '../../srblive/classroom/info?_' + $.now(),
		    	param: vm.srbliveClassroom.id,
		    	success: function(data) {
		    		vm.srbliveClassroom = data;
		    		vm.livetype = vm.srbliveClassroom.livetype;
		    		if(!vm.srbliveClassroom.imageurl){
                        vm.srbliveClassroom.imageurl = "";
                    }
                    //富文本-赋值
                    vm.ue.setContent(htmlDecodeByRegExp(vm.srbliveClassroom.content),false);
		    	}
			});
		},
		acceptClick: function() {
            //富文本-取值
            vm.srbliveClassroom.content = htmlEncodeByRegExp(vm.ue.getContent());

			if (!$('#form').Validform()) {
		        return false;
		    }
		    $.ConfirmForm({
		    	url: '../../srblive/classroom/update?_' + $.now(),
		    	param: vm.srbliveClassroom,
		    	success: function(data) {
		    		$.currentIframe().vm.load();
		    	}
		    });
		},
        getConfig: function () {
            $.getJSON("../../sys/oss/config", function(r){
                vm.config = r.config;
            });
        },
	},
    created: function(){
        this.getConfig();
    },
    beforeCreate:function () {
        //初始化父类型
        Utils.getLiveRoomTypes({
            success:function (result) {
                vm.liveparenttypes = result.rows;
            }
        })
    },
    mounted:function () {
        DateUtils.datetimepicker($('#srbliveClassroom-begintime'),
            {vmTarget: 'srbliveClassroom', property: 'begintime'},
            {
                startDate: new Date().Format("yyyy-MM-dd hh:mm:ss")
            });

        var vm = this;
        //延时绑定辖区的下拉选项，为了辖区下拉数据先加载
        setTimeout(function() {
            vm.srbliveClassroom.livetype = vm.livetype; //延时绑定辖区的下拉选项，为了辖区下拉数据先加载

            AjaxUploadUtils.cloudInit({
                targetId:'imageurl',
                success:function(file, r){
                    vm.srbliveClassroom.imageurl = r.url;
                },
            });
        }, 500);
        // 初始化 textarea 的值
        // editor.txt.html(vm.srbliveClassroom.content);

	},
    computed:{

    }
});